package com.nav.interpreter.brainfuck;

public class Ribbon {
	Node first, current, last;
	public Ribbon() {
		first = current = last = new Node();
	}
	public void shiftRight() {
		if(current == last) {
			current.r = last = new Node();
			last.l = current;
		}
		current = current.r;
	}
	public void shiftLeft() {
		if(current == first) {
			current.l = first = new Node();
			first.r = current;
		}
		current = current.l;
	}
	public void set(char c) {
		current.c = c;
	}
	public char get() {
		return current.c;
	}
	public void increase() {
		current.c++;
	}
	public void decrease() {
		current.c--;
	}
	public String toString() {
		StringBuilder sb = new StringBuilder();
		Node n = first;
		while(n != current) {
			sb.append((int)n.c).append(",");
			n = n.r;
		}
		sb.append((int)current.c).append("*").append(",");
		n = current.r;
		while(n != null) {
			sb.append((int)n.c).append(",");
			n = n.r;
		}
		return sb.toString();
	}
}
